package com.tanhua.server.controller;

import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.VideoMqService;
import com.tanhua.server.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class VideoController {

    @Autowired
    private VideoService videoService;

    @Autowired
    private VideoMqService videoMqService;

    /**
     * 视频列表
     *  请求方式：GET
     *  参数：
     *      page，pagesize
     */
    @GetMapping
    public ResponseEntity queryVideoList(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10")Integer pagesize) {
        if(page <= 0) {
            page = 1;
        }
        PageResult result = videoService.queryVideoList(page,pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     * 发布视频
     *  请求方式：POST
     *  参数：
     *      videoThumbnail ： 封面图
     *      videoFile：视频
     */
    @PostMapping
    public ResponseEntity saveVideo(MultipartFile videoThumbnail,MultipartFile videoFile) throws IOException {
        return videoService.saveVideo(videoThumbnail,videoFile);
    }

    /**
     * 关注用户
     *  请求连接：POST   /:uid/userFocus
     */
    @PostMapping("/{id}/userFocus")
    public ResponseEntity followUser(@PathVariable("id") Long  followUserId) {
        return videoService.followUser(followUserId);
    }


    /**
     * 取消关注用户
     *  请求连接：POST  /:uid/userUnFocus
     */
    @PostMapping("/{id}/userUnFocus")
    public ResponseEntity disFollowUser(@PathVariable("id") Long  followUserId) {
        return videoService.disFollowUser(followUserId);
    }

    /**
     * 视频点赞
     */
    @PostMapping("/{id}/like")
    public ResponseEntity likeComment(@PathVariable("id") String videoId) {
        videoMqService.likeVideoMsg(videoId);
        return videoService.likeComment(videoId);
    }
}
